package cn.itcast.day03.demo01;

public class Computer {
    public void powerOn(){
        System.out.println("笔记本电脑开机");
    }
    public void powerOff(){
        System.out.println("笔记本电脑关机");
    }
    //使用USB接口的方法，使用接口作为方法的参数；
    public void useDevice(USB usb){
        usb.open();
        if(usb instanceof Mouse){ //一定要先判断区分
            System.out.println("该类型对象是否是Mouse类型");
            Mouse mouse = (Mouse) usb;  //向下转型
            mouse.click();
        }else if(usb  instanceof Keyboard){
            System.out.println("该类型对象是否是Keyboard类型");
            Keyboard keyboard = (Keyboard) usb;  //向下转型
            keyboard.type();
        }
        usb.close(); //关闭设备
    }

}
